package com.leyou.trade.web;

import com.leyou.trade.entity.Cart;
import com.leyou.trade.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @PostMapping
    public ResponseEntity<Void> addCatr(@RequestBody Cart cart) {
        this.cartService.addCatr(cart);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @GetMapping("/list")  //获取购物车内商品
    public ResponseEntity<List<Cart>> listCart() {
        return ResponseEntity.ok(cartService.listCart());
    }

    @DeleteMapping("{skuId}")
    public ResponseEntity<Void> deleteCart(@PathVariable("skuId") Long skuId) {
        cartService.deleteCart(skuId);
        return ResponseEntity.noContent().build();
    }

    @PostMapping("/list")  //购物车合并
    public ResponseEntity<Void> addCartItemList(@RequestBody List<Cart> itemList) {
        cartService.addCartItemList(itemList);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }


}
